using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;

namespace _18miljard.Db
{
	public class ConnectionWithTransaction
	{
		private OleDbConnection connection;
		private OleDbTransaction transaction;

		public ConnectionWithTransaction(string connectionString)
		{
			this.connection = new OleDbConnection(connectionString);

			this.Open();

			this.transaction = this.connection.BeginTransaction();
		}

		public void Open()
		{
			this.connection.Open();
		}

		public void Close()
		{
			if (this.connection.State != System.Data.ConnectionState.Closed)
				this.connection.Close();
		}

		public void Commit()
		{
			this.transaction.Commit();
		}

		public void Rollback()
		{
			this.transaction.Rollback();
		}

		public OleDbConnection Connection
		{
			get { return this.connection; }
		}

		public OleDbTransaction Transaction
		{
			get { return this.transaction; }
		}
	}
}
